package com.tf_cut.backend.service.service;


import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.common.pojo.Result;
import com.tf_cut.backend.common.service.CommonServiceImpl;
import com.tf_cut.backend.mapper.ServiceInfoMapper;
import com.tf_cut.backend.seller.service.SellerAccountService;
import com.tf_cut.backend.service.pojo.ServiceInfo;
import com.tf_cut.backend.service.repository.ServiceInfoRepository;
import com.tf_cut.backend.service.vo.ServiceInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Service
@Transactional
@Slf4j
public class ServiceInfoServiceImpl extends CommonServiceImpl<ServiceInfoVo, ServiceInfo, String> implements ServiceInfoService {

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ServiceInfoRepository serviceInfoRepository;
    @Autowired
    private SellerAccountService sellerAccountService;
	@Autowired
	private ServiceInfoMapper serviceInfoMapper;
    
	@Override
	public Result<ServiceInfoVo> insertServiceInfo(ServiceInfoVo svo) {
		Result<ServiceInfoVo> result = this.save(svo);
		result.setData(svo);
		return result;
	}

	@Override
	public PageInfo<ServiceInfoVo> queryServiceInfoList(ServiceInfoVo serviceInfoVo) {
		com.github.pagehelper.PageHelper.startPage(serviceInfoVo.getPage(), serviceInfoVo.getRows());
		List<ServiceInfoVo> list = serviceInfoMapper.findListServiceInfo(serviceInfoVo);
		com.github.pagehelper.PageInfo<ServiceInfoVo> pageInfo = new com.github.pagehelper.PageInfo<>(list);

		PageInfo<ServiceInfoVo> returnPageInfo = new PageInfo<>();
		returnPageInfo.setPage(pageInfo.getPageNum());
		returnPageInfo.setPageSize(pageInfo.getPageSize());
		returnPageInfo.setRows(pageInfo.getList());
		returnPageInfo.setRecords((int) pageInfo.getTotal());
		returnPageInfo.setTotal(pageInfo.getPages());
		return returnPageInfo;
	}
}
